fixes
authorHerman J. Radtke III <herman@hermanradtke.com>
Tue, 9 May 2017 05:30:23 +0000 (22:30 -0700)
committerHerman J. Radtke III <herman@hermanradtke.com>
Tue, 9 May 2017 05:30:23 +0000 (22:30 -0700)
- fix glob missing members test to use proper expectations
- update code to handle case where glob does not match anything

src/cargo/core/workspace.rs
tests/workspaces.rs

index 0054586c945c892dbfcae4be5b85fe815a5bbe85..6c81bd8e827b0394267f0330dd2ee441fb6a9e3d 100644 (file)
@@ -322,8 +322,16 @@ impl<'cfg> Workspace<'cfg> {
 
             let mut expanded_list = Vec::new();
             for path in list {
-                let expanded_paths = expand_member_path(&path, root)?;
-                expanded_list.extend(expanded_paths);
+                let pathbuf = root.join(path);
+                let expanded_paths = expand_member_path(&pathbuf)?;
+
+                // If glob does not find any valid paths, then put the original
+                // path in the expanded list to maintain backwards compatibility.
+                if expanded_paths.is_empty() {
+                    expanded_list.push(pathbuf);
+                } else {
+                    expanded_list.extend(expanded_paths);
+                }
             }
 
             for path in expanded_list {
@@ -536,8 +544,7 @@ impl<'cfg> Workspace<'cfg> {
     }
 }
 
-fn expand_member_path(member_path: &str, root_path: &Path) -> CargoResult<Vec<PathBuf>> {
-    let path = root_path.join(member_path);
+fn expand_member_path(path: &Path) -> CargoResult<Vec<PathBuf>> {
     let path = path.to_str().unwrap();
     let res = glob(path).map_err(|e| {
         human(format!("could not parse pattern `{}`: {}", &path, e))
index 4a1f3bb63a7a8f79151bf62a0598ea12a39bcaf8..4670d28f77af30315a5d2cab3c80b6386f509e91 100644 (file)
@@ -1444,7 +1444,7 @@ fn glob_syntax() {
 }
 
 #[test]
-fn glob_syntax_non_cargo_folder() {
+fn glob_syntax_invalid_members() {
     let p = project("foo")
         .file("Cargo.toml", r#"
             [project]
@@ -1459,10 +1459,13 @@ fn glob_syntax_non_cargo_folder() {
         .file("crates/bar/src/main.rs", "fn main() {}");
     p.build();
 
-    assert_that(p.cargo("build"), execs().with_status(0));
-    assert_that(&p.bin("foo"), existing_file());
-    assert_that(&p.bin("bar"), is_not(existing_file()));
+    assert_that(p.cargo("build"),
+                execs().with_status(101)
+                       .with_stderr("\
+error: failed to read `[..]Cargo.toml`
 
-    assert_that(&p.root().join("Cargo.lock"), existing_file());
+Caused by:
+  [..]
+"));
 }